package com.app.lcl.model;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.app.lcl.entities.Name;
import com.app.lcl.entities.Person;
import com.app.lcl.utils.HibernateUtil;

public class PersonManager {
	private void createAndStorePerson() {
		
		//打开线程安全的的session对象
		Session session=HibernateUtil.currentSession();
		//打开事务
		Transaction tx=session.beginTransaction();
		//创建Person对象
		Person lcl=new Person();
		lcl.setAge(23);
		
		//Name n1=new Name("李","成龙");
		
		Name n=new Name();
		n.setFirst("李");
		n.setSecond("成龙");
		lcl.setName(n);
		lcl.setId(17);
		//创建List集合
		List<String> schools=new ArrayList<String>();
		schools.add("小学");
		schools.add("中学");
		lcl.setSchools(schools);
		
		session.save(lcl);
		tx.commit();
		HibernateUtil.closeSession();
	}
}

